import {
	defineStore
} from 'pinia';

const useLoginStore = defineStore('login', {
	state: () => ({
		token: uni.getStorageSync('token') || "",
		userinfo: uni.getStorageSync('userinfo') || {}
	}),
	actions: {
		changeToken(value) {
			this.token = value;
			uni.setStorageSync('token', value)
		},
		changeUserinfo(value) {
			this.userinfo = value;
			this.token = value.token;
			uni.setStorageSync('token', value.token)
			uni.setStorageSync('userinfo', value)
		},

		outLogin() {
			this.token = null;
			uni.removeStorageSync('token')
		}
	}
});

export default useLoginStore;